import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 装箱问题
 * User: wangxin
 * Date: 2024-08-09
 * Time: 16:59
 */
public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        int V = in.nextInt();
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i =0;i< arr.length;i++){
            arr[i] = in.nextInt();
        }


        System.out.println( maxV(arr,V));

    }
    public static int maxV(int[] arr,int V) {
        int[] dp = new int[V + 1];
        for (int i = 0; i < arr.length; i++) {
            for (int j = V; j > 0; j--) {
                if (j >= arr[i]) {
                    dp[j] = Math.max(dp[j], dp[j - arr[i]] + arr[i]);
                }
            }
        }
        return V - dp[V];
    }
}
